package com.bwie.orders.sync;

import com.bwie.common.core.utils.StringUtils;
import com.bwie.common.redis.service.RedisService;
import com.bwie.orders.domain.po.PmsSkuInfo;
import com.bwie.orders.mapper.PmsSkuInfoMapper;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Component
public class RedisHandler implements InitializingBean {
    // 当实现了该接口的类的所有bean属性被设置后，Spring容器将会调用这个方法
   @Autowired
   private PmsSkuInfoMapper pmsSkuInfoMapper;

    @Autowired
    private RedisService redisService;
    @Override
    public void afterPropertiesSet() throws Exception {

        // 查询商品信息
        List<PmsSkuInfo> pmsSkuInfos = pmsSkuInfoMapper.selectSkuInfoList();

      //不能为空
       if(!StringUtils.isEmpty(pmsSkuInfos)){

         for (PmsSkuInfo pmsSkuInfo : pmsSkuInfos) {
             Long skuId = pmsSkuInfo.getSkuId();

             // 预热到redis里面 设置过期时间 防止雪崩
             long longTime = RandomUtils.nextLong(1, 60);
//             redisService.setCacheObject("ProductInventoryLhc:"+skuId.toString(), pmsSkuInfo.getSkuNum(), longTime, TimeUnit.HOURS);
         }

      }





    }



}





